home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-10-24 | 2.4 KB | 82 lines | [UVtx/UVtl] |
- //////////////////////////////////////////////////////////
- // This program demonstrates reading the mouse location //
- // and displaying its coords in a continueous way. If //
- // the mouse button is clicked, the line and coords //
- // turn red. //
- // As usual, abort by cmd-. //
- //////////////////////////////////////////////////////////
-
- white = "65535,65535,65535"
- black = "0,0,0"
- red = "65535,0,0"
- Width 2
- // repeat forever -- read the mouse location and draw it
- Repeat 10000000
- drawXY(mouseX(), mouseY())
-
- // // // // // //
-
- ///////////////////////////////////////////////////////
- // function drawXY: display the mouse (x,y) coords, //
- // and draw a line from (0,0) to (x,y). //
- ///////////////////////////////////////////////////////
- Function drawXY(x, y)
- If (! defined(lastX)) // very first time
- lastX = 0
- lastY = 0
-
- // return if no change -- this will avoid flicker
- If (x = lastX & y = lastY)
- Return
- // get here if a new mouse location
-
- // display the coords, erase old line and draw new
- printLoc(x, y)
- if ( click(0) )
- color = red
- else
- color = black
- lineFrom00(lastX, lastY, white)
- lineFrom00(x, y, color)
-
- // update the "old" mouse location to current
- lastX = x
- lastY = y
-
-
- ///////////////////////////////////////////////////////
- // function printLoc - draw a yellowish rectangle as //
- // background, print the coords in it //
- ///////////////////////////////////////////////////////
- Function printLoc(x, y)
- // rectangle as background
- Up
- Goto -width()/2, height()/2,0
- Down
- Fill 1,64398,65535,35928 // yellowish
- Repeat 2
- Forward 120
- Right 90
- Forward 17
- Right 90
- // now print the coords.
- Up
- Right 45
- Forward 18
- Print "x=" . x . " y=". y
-
-
- ///////////////////////////////////////////////////////////
- // function lineFrom00 - draw a line from (0,0) to (x,y) //
- // with a given R,G,B color //
- ///////////////////////////////////////////////////////////
- Function lineFrom00(x, y, color)
- // erase old line, draw a line from (0,0) to
- // the mouse location, then draw a diamond at (0,0)
- Color color
- Up
- Goto x, y, 0
- Down
- Goto 0,0,0
-
-